#version 450

layout(location=0)      in vec3 a_Pos;
layout(location=1)      in vec3 a_Color;
layout(location=2)      in vec4 a_Joint;
layout(location=3)      in vec4 a_Weight;
layout(location=4)      in vec4 a_ModelMat0;
layout(location=5)      in vec4 a_ModelMat1;
layout(location=6)      in vec4 a_ModelMat2;
layout(location=7)      in vec4 a_ModelMat3;

layout(set=0, binding=0, std140) buffer Joints{
    mat4 joints[];
};

out gl_PerVertex{
    float gl_PointSize;
    vec4 gl_Position;
};

layout(location=0) out vec3 v_Color;

void main(){
    mat4 modelMat = mat4(a_ModelMat0,  a_ModelMat1, a_ModelMat2, a_ModelMat3);
    vec4 pos = vec4(a_Pos, 1.f);
    if (joints.length() > 1) {
        pos = mat4(joints[int(a_Joint.x)] * a_Weight.x +
                   joints[int(a_Joint.y)] * a_Weight.y +
                   joints[int(a_Joint.z)] * a_Weight.z +
                   joints[int(a_Joint.w)] * a_Weight.w) * pos;
    }
    gl_Position = modelMat * pos;
    gl_PointSize = 3.0;
    v_Color = a_Color;
}